<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <h1 :style="{opacity}">HelloVue</h1>
    <button @click="$destroy()">销毁vm</button>
</div>
<script src="../../JavaScript/vue.js"></script>
<script>
    const vm = new Vue({
        el: "#app",
        data: {
            opacity: 1,
            time: null
        },
        mounted() {
            this.time = setInterval(() => {
                this.opacity -= 0.01
                if (this.opacity <= 0) {
                    this.opacity = 1
                }
                console.log("定时器开启")
            }, 10)
        },
        beforeDestroy() {
            clearInterval(this.time)
        }

    })
</script>
</body>
</html>

